Repository navigation
fix(cas): create the conversation and start its session on chat init [JAR-10400] - #215
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Toggling readOnly leaves sessionReady resolved to the ended session, causing subsequent sends to target it instead of the newly started session.
1 open issue
What changed in this PR
This PR addresses JAR-10400 by creating conversations and starting sessions during chat initialization, rather than waiting for the first message, to prevent Flows from getting stuck at Wait-for-Message.
Changes:
- Centralizes conversation creation and session cleanup across load, New Chat, and conversation switches.
- Shares pending creates across sends, attachments, and settings updates, with timeout and stale-result handling.
- Adds lifecycle regression tests and updates the lifecycle documentation.
| File | Description |
|---|---|
packages/conversational-agent-chat/src/ConversationalAgentChat.tsx |
Implements upfront creation, effect-owned sessions, and pending-operation handling. |
packages/conversational-agent-chat/src/__tests__/ConversationalAgentChat.test.tsx |
Adds coverage for initialization, retries, switching, and unmount behavior. |
packages/conversational-agent-chat/agents.md |
Documents the revised conversation and session lifecycle. |
Review effort: Balanced
📊 Coverage Report
|
e27a890 to
f5d5578
Compare
f5d5578 to
a9188d0
Compare
a9188d0 to
e488497
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A pending history request can overwrite an updated conversation label with the original create-response label because the merge uses a stale active-conversation reference.
1 open issue
1 resolved since last review
Review effort: Balanced
e488497 to
db13ec6
Compare
There was a problem hiding this comment.
🟡 Changes recommended
An in-flight send can use a replacement conversation’s session or an ended session because cancellation is not checked across awaits, risking delivery to the wrong conversation.
1 open issue
1 resolved since last review
Review effort: Balanced
db13ec6 to
50345b4
Compare
…[JAR-10400] The widget created the conversation on the first send and started the session with it, so the create, session start and first exchange all reached CAS together, which can leave a chat Flow stuck at Wait-for-Message. The session also never started before the first send, unlike the react-sdk, which Temporal agents rely on. - One session effect owns the active conversation's session: it starts as soon as a conversation is active (load, New Chat, inputs form, existing conversation, history switch) and ends on switch or unmount. Ended and read-only conversations get no session. - startConversation() is the only create path. Load and New Chat create up front behind the mounted chat; sends, attachments and the settings panel join the in-flight create. A failed or timed-out (30s) create shows a banner and the next send retries. - Work waiting on a conversation the user or host moved away from is dropped silently; a superseded init run stops at its next await. - The settings panel can apply optional inputs before the first message, and a conversation created while the first history page loads stays in the sidebar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50345b4 to
f7ce6aa
Compare
| @@ -11,6 +11,7 @@ import { getI18n } from "../i18n"; | |||
| import { ConversationalAgentChat } from "../ConversationalAgentChat"; | |||
| import { UiPath } from "@uipath/uipath-typescript/core"; | |||
There was a problem hiding this comment.
From the first demo video in your PR - the "Generating..." disappears fast for that Flow chat agent (it seems like its disappearing right at the end of the agent response). Just checking that it doesn't stop showing the "Generating..." until the end-exchange event?
There was a problem hiding this comment.
yes, the widget only stops showing the generating onExchangeEnd or when the user hits stop
| const hasRequiredInputs = (schema: InputSchema | null | undefined) => | ||
| (schema?.required?.length ?? 0) > 0; |
There was a problem hiding this comment.
Oh thanks - so there was a bug before with optional inputs and it works now (directly initializes the chat just like no-inputs, when inputs are all optional)
There was a problem hiding this comment.
optional-only inputs already skipped the form on develop I believe. The only change is that the conversation is now created on load instead of on the first send, same as agents with no inputs.
| // The only way a conversation is created. Everything that needs one (load, | ||
| // New Chat, the inputs form, a send, an attachment, the settings panel) | ||
| // joins the one in-flight create rather than starting a second. |
There was a problem hiding this comment.
Can we rewrite the comments across all the changes to be a bit more explanatory / human-readable? I think Claude is kinda verbose sometimes / unnecessary in its details :)
| // For the creates nothing awaits (load, New Chat): a failure becomes a | ||
| // banner, and the next send retries. |
There was a problem hiding this comment.
Out of curiosity, what does the screen look like when a load/new-chat fails? Could you add a screenshot of that to the PR description
There was a problem hiding this comment.
added a short video to the PR description
| // Load and New Chat create the conversation up front under the same rule. | ||
| const shouldCreateUpfront = useCallback( | ||
| (agent: AgentGetByIdResponse | null | undefined, requiredInputs: boolean) => | ||
| !!agent && !requiredInputs && !readOnly && !isDebugMode, |
There was a problem hiding this comment.
Nice - i see the !isDebugMode. Just verifying that you tested debug mode as well end-to-end, where you pass in the debug chat id?
There was a problem hiding this comment.
the unit tests cover it, but will test it in flow and add a video to the PR description
| // The only way a conversation is created. Everything that needs one (load, | ||
| // New Chat, the inputs form, a send, an attachment, the settings panel) | ||
| // joins the one in-flight create rather than starting a second. | ||
| const startConversation = useCallback( |
There was a problem hiding this comment.
Not sure if important but my coding agent suggested:
startConversation(agentInput) silently drops agentInput when a create is already pending. if (pendingCreate.current) return pendingCreate.current; returns the in-flight create regardless of arguments, so an inputs-form submit would adopt an input-less conversation. Unreachable today only because shouldCreateUpfront returns false when the agent has required inputs — an invariant held at a distance with nothing local enforcing it. A future change (pre-creating for required-input agents, say) would produce conversations missing their required inputs, failing agent-side rather than at compile time. Cheapest fix: skip the dedupe when agentInput is passed, or assert.
There was a problem hiding this comment.
good catch, should be fixed now
| const [activation, setActivation] = useState<{ | ||
| conversation: ConversationCreateResponse | null; | ||
| }>({ conversation: null }); | ||
| const activeConversationRef = useRef<ConversationCreateResponse | null>(null); | ||
| // Bumped whenever the active conversation changes, so a create started for | ||
| // an earlier one never becomes active. | ||
| const conversationGeneration = useRef(0); | ||
| // The in-flight create, shared by everything waiting on a conversation. | ||
| const pendingCreate = useRef<Promise<ConversationCreateResponse> | null>( | ||
| null, | ||
| ); | ||
| // Conversations this widget created, so the first history page (which can | ||
| // land after the create) doesn't drop the active one from the sidebar. | ||
| const createdConversationIds = useRef(new Set<string>()); | ||
| // Bumped per init run (and on unmount) so a superseded run stops at its next await. | ||
| const initRun = useRef(0); |
There was a problem hiding this comment.
Can we simplify all these at all? Claude suggested:
conversationGeneration is redundant. It's checked in exactly two places (lines 939, 953), and the .finally three lines below already demonstrates the equivalent test:
if (pendingCreate.current === pending) pendingCreate.current = null;
Every path that bumps the generation also nulls pendingCreate — activateConversation (824–825) and the unmount cleanup (2119–2120), and there is no third. So pendingCreate.current !== pending detects supersession in exactly the same cases. Arguably it's more correct: a future "cancel this create" path would be caught by promise identity and missed by a generation that only tracks conversation changes. The counter reads more intentionally, so it's a judgment call rather than a defect — but it's one less invariant to keep in sync.createdConversationIds can be a boolean. It's consulted once, and only ever as has(active.id) — the merge concerns the currently-active conversation and nothing else. One flag set in activateConversation does the same job without a Set that grows for the session's life. Slight nuance: with a Set, leaving a created conversation and reopening it from history keeps it pinnable; with a flag it wouldn't. That difference is close to immaterial, since by then it's in the server page anyway.
There was a problem hiding this comment.
both done, thanks
- Detect a superseded create by checking it's still the pending one, instead of a separate generation counter. - Track whether the active conversation was created here with a flag instead of a Set of ids. - If inputs are passed while a create without them is in flight, attach them with updateById rather than dropping them. - Rewrite the lifecycle comments to be shorter and clearer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Summary
Fixes chat Flows getting stuck at Wait-for-Message (JAR-10400), found on alpha.
The widget created the conversation on the first send and started its session at the same time, so the create, the session start and the first exchange all reached CAS together. That can lose the first message on the Flow side, leaving the Flow waiting forever. The session also never started until the first send, unlike the react-sdk, which starts it as soon as a conversation is selected (Temporal agents rely on this).
This now matches the react-sdk: the conversation is created on load and on New Chat, and its session starts right away.
Changes
ConversationalAgentChat.tsx:startConversation()is the only create path. Load and New Chat create up front while the chat is already showing. A message, attachment or settings-panel input sent during the create waits for it and uses the same conversation. If the create fails or takes longer than 30 seconds, a banner is shown and the next send retries.agents.mdis updated to describe the new lifecycle.Testing
developor when its safeguard is removed.vitest runinconversational-agent-chat: 451 pass.tsc, ESLint, Prettier and the package build are clean.POST /conversationandstartSessiongo out on load before any input, and the first send reuses that session.Demos
Screen.Recording.2026-11-23.at.10.32.01.AM.mov
Screen.Recording.2026-11-23.at.10.33.41.AM.mov
Screen.Recording.2026-11-23.at.10.35.58.AM.mov
Screen.Recording.2026-11-24.at.10.54.38.AM.mov
Screen.Recording.2026-11-24.at.11.28.54.AM.mov
🤖 Generated with Claude Code